home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 16 / Computer Interactive cdrom 16 - dic 98.iso / zdnetit / content / CMATHCC.ZIP / INCLUDE.ZIP / NEWCPLX.H < prev   
Encoding:
C/C++ Source or Header  |  1998-09-01  |  62.6 KB  |  1,341 lines

  1. /* newcmplx.h
  2.  
  3.     Include-File for the CMATH Complex Number Library
  4.     replaces <complex.h>.
  5.  
  6.     Copyright (C) 1996-1998 Martin Sander
  7.     Address of the author:
  8.            Martin Sander 
  9.            Sertⁿrnerstr. 11
  10.            D-37085 G÷ttingen
  11.            Germany
  12.            e-mail: MartinSander@Bigfoot.com
  13.  
  14.     for C++, the following classes are defined:
  15.     a) if you choose the "classic" Borland C++ style:  class complex;
  16.     b) otherwise:
  17.        classes complex<float>, complex<double>, and complex<long double>.
  18.     fComplex, dComplex, and eComplex are defined as synonyms for these classes.
  19.  
  20.     Fo plain C, use <cmath.h> instead, which declares fComplex, dComplex,
  21.     and eComplex as structs, along with the same range of functions as
  22.     present in the complex C++ classes.
  23.  
  24.     The classes complex and complex<double> are binary compatible with
  25.     the C struct dComplex. Similarly, complex<float> and struct fComplex
  26.     as well as class complex<long double> and struct eComplex are mutually
  27.     compatible. This is important if one has programs with some modules
  28.     written in C, others in C++.
  29.  
  30.     All mathematical complex functions are implemented as a library
  31.     written in Assembler language. In comparison to C++ inline functions,
  32.     this leads to greater precision, greater speed and best security due
  33.     to complete error handling via the standard C error handling functions
  34.     _matherr() (for complex<float> and complex<double>)
  35.     and _matherrl() (for complex<long double>).
  36.  
  37.     The declarations for the Standard Library complex classes have
  38.     partly been adapted from the implementation by Rogue Wave Software, Inc.
  39.     The function bodies, however, are completely new.
  40.  
  41.     Note the following important differences between this implementation
  42.     and the one contained in <complex.h>:
  43.     -  The real and imaginary parts are declared as public and are referred
  44.        to as  Re and Im, so that you may always access them as z.Re and z.Im
  45.        in addition to the member functions real(z) and imag(z);
  46.     -  The argument of all mathematical functions is a value, not a reference.
  47.     -  The following functions and operators have been added:
  48.        friend complex  cubic(complex);  //   third power
  49.        friend complex  inv(complex);    //   1.0 / z
  50.        friend complex  ipow(complex __base, int __expo);  // integer power
  51.        friend complex  log2(complex);
  52.        friend complex  powReExpo(complex __base, double __expoRe);
  53.                                        // explicit power with real exponent
  54.        friend complex  powReBase(double __baseRe, complex __expo);
  55.                                        // explicit power of real base
  56.        friend complex  quartic(complex);  // fourth power
  57.        friend complex  square(complex);
  58.        friend int      operator==(complex &, double);
  59.        friend int      operator!=(complex &, double);
  60.        Also new are many of the mixed-accuracy level binary operators.
  61. */
  62.  
  63. #ifndef __cplusplus
  64. #error Must use C++ for complex classes. Include <cmath.h> for the plain-C version
  65. #endif
  66. #if !defined(__NEWCPLX_H)
  67. #define __NEWCPLX_H
  68.  
  69.  
  70.       /* define _VFAR to get around the buggy definition of _FAR : */
  71. #if defined __SMALL__ || defined __MEDIUM__
  72.      #define   _VFAR  near   /* even in case of DS!=SS  */
  73. #elif defined __FLAT__ || defined _WIN32
  74.      #define  _VFAR
  75. #else
  76.      #define   _VFAR  far
  77. #endif
  78. #ifdef __BORLANDC__
  79.      #pragma option -a-
  80.      #if (__BORLANDC__ >= 0x450)
  81.          #define __cmf _RTLENTRY _EXPFUNC
  82.          #define __cmo _RTLENTRY
  83.     #else
  84.          #define __cmf  _Cdecl _FARFUNC
  85.          #define __cmo  _Cdecl
  86.     #endif
  87.     #if __BORLANDC__ < 0x500
  88.         #define VBOOL int
  89.     #else
  90.         #define VBOOL bool
  91.     #endif
  92. #else /* Visual C++, Watcom */
  93.      #pragma pack( push,1 )
  94.      #define VBOOL int
  95.      #define __cmf _cdecl
  96.      #define __cmo _cdecl
  97. #endif /* avoid insertion of dummy bytes  */
  98.  
  99. #if !defined(__IOSTREAM_H)
  100. #include <iostream.h>
  101. #endif
  102.  
  103. #if defined( CMATH_CLASSIC_COMPLEX )
  104.       // classic Borland C++ class complex only. This has double precision.
  105.       // complex numbers of float and of long double precision are
  106.       // implemented as structs. So there is no constructor! Moreover, there
  107.       // are no functions defined for the float and long double complex numbers.
  108. #if !defined(__IOSTREAM_H)
  109. #include <iostream.h>
  110. #endif
  111.  
  112. #if !defined(RC_INVOKED)
  113.  
  114. #if defined(__BCOPT__)
  115. #if !defined(__FLAT__) && ((__BORLANDC__ < 0x450) || !defined(_RTL_ALLOW_po))
  116. #pragma option -po-     // disable Object data calling convention
  117. #endif
  118. #endif
  119.  
  120. #pragma option -Vo-
  121.  
  122. #if defined(__STDC__)
  123. #pragma warn -nak
  124. #endif
  125.  
  126. #endif  /* !RC_INVOKED */
  127.  
  128. #if(__BORLANDC__ >= 0x450)
  129. class _EXPCLASS complex {
  130. #else
  131. _CLASSDEF(complex)
  132. class _CLASSTYPE complex {
  133. #endif
  134.   public:
  135.     // constructors
  136.     complex( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  137.     complex( double Re_part )  {Re=Re_part; Im=0;}
  138.     complex() {}; // more efficient to have these three separate variants
  139.     // Cartesian complex from polar coordinates:
  140.     friend complex __cmf polar(double _mag, double _angle=0);
  141.     // basic operations:
  142.     double real() { return Re; }                     // real part
  143.     double real(complex _VFAR &_z) { return _z.Re; }
  144.     double imag() { return Im; }                     // imaginary part
  145.     double imag(complex _VFAR &_z) { return _z.Im; } // imaginary part
  146.     friend complex __cmf neg(complex _VFAR &);   // same as unary operator -
  147.     friend complex __cmf conj(complex _VFAR &);  // complex conjugate
  148.     friend double  __cmf norm(complex _VFAR &);  // square of the magnitude
  149.     friend double  __cmf arg(complex);           // angle in the plane
  150.  
  151.      // Unary operators
  152.     complex _VFAR & __cmo operator+();
  153.     friend complex _VFAR & __cmf operator-( complex _VFAR &);
  154.  
  155.     // Binary operators
  156.     friend complex __cmf operator+(complex _VFAR &, complex _VFAR &);
  157.     friend complex __cmf operator+(double, complex _VFAR &);
  158.     friend complex __cmf operator+(complex _VFAR &, double);
  159.     friend complex __cmf operator-(complex _VFAR &, complex _VFAR &);
  160.     friend complex __cmf operator-(double, complex _VFAR &);
  161.     friend complex __cmf operator-(complex _VFAR &, double);
  162.     friend complex __cmf operator*(complex _VFAR &, complex _VFAR &);
  163.     friend complex __cmf operator*(complex _VFAR &, double);
  164.     friend complex __cmf operator*(double, complex _VFAR &);
  165.     friend complex __cmf operator/(complex _VFAR &, complex _VFAR &);
  166.     friend complex __cmf operator/(complex _VFAR &, double);
  167.     friend complex __cmf operator/(double, complex _VFAR &);
  168.  
  169.     friend VBOOL __cmf operator==(complex _VFAR &, complex _VFAR &);
  170.     friend VBOOL __cmf operator==(complex _VFAR &, double);
  171.     friend VBOOL __cmf operator!=(complex _VFAR &, complex _VFAR &);
  172.     friend VBOOL __cmf operator!=(complex _VFAR &, double);
  173.  
  174.     complex _VFAR & __cmo operator+=(complex _VFAR &);
  175.     complex _VFAR & __cmo operator+=(double);
  176.     complex _VFAR & __cmo operator-=(complex _VFAR &);
  177.     complex _VFAR & __cmo operator-=(double);
  178.     complex _VFAR & __cmo operator*=(complex _VFAR &);
  179.     complex _VFAR & __cmo operator*=(double);
  180.     complex _VFAR & __cmo operator/=(complex _VFAR &);
  181.     complex _VFAR & __cmo operator/=(double);
  182.  
  183.     // Overloaded ANSI C math functions with error handling via matherr():
  184.     friend double  __cmf abs(complex);    // complex pointer magnitude
  185.     friend complex __cmf acos(complex);
  186.     friend complex __cmf asin(complex);
  187.     friend complex __cmf atan(complex);
  188.     friend complex __cmf cos(complex);
  189.     friend complex __cmf cosh(complex);
  190.     friend complex __cmf cubic(complex);  // raise to the third power
  191.     friend complex __cmf exp(complex);
  192.     friend complex __cmf inv(complex);    //   1.0 / z
  193.     friend complex __cmf ipow(complex _base, int _IntExpo);  // integer power
  194.     friend complex __cmf ln(complex);
  195.     friend complex __cmf log(complex); // same as ln
  196.     friend complex __cmf log2(complex);
  197.     friend complex __cmf log10(complex);
  198.     friend complex __cmf pow(complex _base, double _expoRe);
  199.     friend complex __cmf powReExpo(complex _base, double _expoRe);
  200.     friend complex __cmf pow(double _baseRe, complex _expo);
  201.     friend complex __cmf powReBase(double _baseRe, complex _expo);
  202.     friend complex __cmf pow(complex _base, complex _expo);
  203.     friend complex __cmf quartic(complex);  // raise to the fourth power
  204.     friend complex __cmf sin(complex);
  205.     friend complex __cmf sinh(complex);
  206.     friend complex __cmf sqrt(complex);
  207.     friend complex __cmf square(complex);
  208.     friend complex __cmf tan(complex);
  209.     friend complex __cmf tanh(complex);
  210.  
  211.     friend ostream _VFAR & __cmf operator<<(ostream _VFAR &, complex _VFAR &);
  212.     friend istream _VFAR & __cmf operator>>(istream _VFAR &, complex _VFAR &);
  213.  
  214. // Implementation
  215.     double Re, Im;   // still public!
  216. };
  217. #if !defined( _CMATH_DEFS )
  218.    #define _CMATH_DEFS
  219.    typedef struct {float  Re, Im;} fComplex;
  220.    typedef complex  dComplex;
  221.    #ifdef __BORLANDC__
  222.        typedef long double  extended;
  223.        typedef struct {extended Re, Im;} eComplex;
  224.    #else /* Visual C++ */
  225.        typedef  double extended; /* Visual C++ does not support
  226.                                  80-bit IEEE numbers. So make
  227.                                  extended equal to double    */
  228.        typedef dComplex  eComplex;
  229.    #endif    /* restore default data packing  */
  230. #endif
  231.  
  232. // Inline implementation of the simplest functions and operators
  233. // basic operations:
  234. inline complex __cmo conj(complex _VFAR & __z)
  235. {    return complex(__z.Re, -__z.Im); }
  236.  
  237. inline complex __cmo neg(complex _VFAR & __z)
  238. {    return complex(-__z.Re, -__z.Im); }
  239.  
  240. // unary operators:
  241. inline complex _VFAR & __cmo complex::operator+()
  242. {    return *this; }
  243.  
  244. inline complex _VFAR & __cmf operator-( complex _VFAR & __z)
  245. {    return complex(-__z.Re, -__z.Im); }
  246.  
  247.  
  248. // binary operators:
  249. inline complex __cmo operator+(complex _VFAR & __z1, complex _VFAR & __z2)
  250. {    return complex(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  251.  
  252. inline complex __cmo operator+(double __z1Re, complex _VFAR & __z2)
  253. {    return complex(__z1Re + __z2.Re, __z2.Im); }
  254.  
  255. inline complex __cmo operator+(complex _VFAR & __z1, double __z2Re)
  256. {    return complex(__z1.Re + __z2Re, __z1.Im); }
  257.  
  258. inline complex __cmo operator-(complex _VFAR & __z1, complex _VFAR & __z2)
  259. {    return complex(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  260.  
  261. inline complex __cmo operator-(double __z1Re, complex _VFAR & __z2)
  262. {    return complex(__z1Re - __z2.Re, -__z2.Im); }
  263.  
  264. inline complex __cmo operator-(complex _VFAR & __z1, double __z2Re)
  265. {    return complex(__z1.Re - __z2Re, __z1.Im); }
  266.  
  267. inline complex __cmo operator*(complex _VFAR & __z1, complex _VFAR & __z2)
  268. {   return complex( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  269.                     __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  270. }
  271.  
  272. inline complex __cmo operator*(complex _VFAR & __z1, double __z2Re)
  273. {    return complex(__z1.Re*__z2Re, __z1.Im*__z2Re); }
  274.  
  275. inline complex __cmo operator*(double __z1Re, complex _VFAR & __z2)
  276. {    return complex(__z2.Re*__z1Re, __z2.Im*__z1Re); }
  277.  
  278. inline complex __cmo operator /(complex _VFAR & __dividend,
  279.                                 complex _VFAR & __divisor )
  280. {     complex     Result;
  281.       long double denom;
  282.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  283.                             __dividend.Im *__divisor.Im) /
  284.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  285.                   (long double)(__divisor.Im) * __divisor.Im));
  286.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  287.                             __dividend.Re * __divisor.Im ) / denom);
  288.       return Result;
  289. }
  290.  
  291. inline complex __cmo operator/(complex _VFAR & __dividend, double __divisorRe)
  292. {    return complex(__dividend.Re/__divisorRe, __dividend.Im/__divisorRe); }
  293.  
  294. inline complex __cmo operator /( double __dividendRe, complex _VFAR & __divisor )
  295. {     complex     Result;
  296.       long double denom;
  297.       Result.Re = (double)((__dividendRe * __divisor.Re) /
  298.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  299.                   (long double)(__divisor.Im) * __divisor.Im));
  300.       Result.Im = -(double)((__dividendRe * __divisor.Im ) / denom);
  301.       return Result;
  302. }
  303.  
  304. inline complex _VFAR & __cmo complex::operator+=(complex _VFAR & __z2)
  305. {   Re += __z2.Re;
  306.     Im += __z2.Im;
  307.     return *this;
  308. }
  309.  
  310. inline complex _VFAR & __cmo complex::operator+=(double __z2Re)
  311. {   Re += __z2Re;
  312.     return *this;
  313. }
  314.  
  315. inline complex _VFAR & __cmo complex::operator-=(complex _VFAR & __z2)
  316. {   Re -= __z2.Re;
  317.     Im -= __z2.Im;
  318.     return *this;
  319. }
  320.  
  321. inline complex _VFAR & __cmo complex::operator-=(double __z2Re)
  322. {   Re -= __z2Re;
  323.     return *this;
  324. }
  325.  
  326. inline complex _VFAR & __cmo complex::operator*=(double __z2Re)
  327. {   Re *= __z2Re;
  328.     Im *= __z2Re;
  329.     return *this;
  330. }
  331.  
  332. inline complex _VFAR & __cmo complex::operator *=(complex _VFAR & __z2)
  333. {     double tmpRe = Re * __z2.Re - Im * __z2.Im;
  334.              Im    = Re * __z2.Im + Im * __z2.Re;
  335.       Re = tmpRe;
  336.       return *this;
  337. }
  338.  
  339. inline complex _VFAR & __cmo complex::operator /=( complex _VFAR & __divisor )
  340. {     long double denom;
  341.       double tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  342.         (denom = (long double)(__divisor.Re) * __divisor.Re +
  343.                  (long double)(__divisor.Im) * __divisor.Im));
  344.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  345.       Re = tmpRe;
  346.       return *this;
  347. }
  348.  
  349. inline complex _VFAR & __cmo complex::operator/=(double __z2Re)
  350. {   Re /= __z2Re;
  351.     Im /= __z2Re;
  352.     return *this;
  353. }
  354.  
  355. inline VBOOL __cmo operator==(complex _VFAR & __z1, complex _VFAR & __z2)
  356. {   return __z1.Re == __z2.Re && __z1.Im == __z2.Im; }
  357.  
  358. inline VBOOL __cmo operator==(complex _VFAR & __z1, double __z2Re)
  359. {   return __z1.Re == __z2Re && __z1.Im == 0.0; }
  360.  
  361. inline VBOOL __cmo operator!=(complex _VFAR & __z1, complex _VFAR & __z2)
  362. {   return __z1.Re != __z2.Re || __z1.Im != __z2.Im; }
  363.  
  364. inline VBOOL __cmo operator!=(complex _VFAR & __z1, double __z2Re)
  365. {   return __z1.Re != __z2Re || __z1.Im != 0.0; }
  366.  
  367.  
  368. #if !defined(RC_INVOKED)
  369.  
  370. #if defined(__STDC__)
  371. #pragma warn .nak
  372. #endif
  373.  
  374. #pragma option -Vo.
  375.  
  376. #if defined(__BCOPT__)
  377. #if !defined(__FLAT__) && ((__BORLANDC__ < 0x450) || !defined(_RTL_ALLOW_po))
  378. #pragma option -po.     // restore Object data calling convention
  379. #endif
  380. #endif
  381.  
  382. #endif  /* !RC_INVOKED */
  383. #if !defined( _CMATH_DEFS )
  384.    #define _CMATH_DEFS
  385.    typedef struct {float  Re, Im;} fComplex;
  386.    typedef complex  dComplex;
  387.    #ifdef __BORLANDC__
  388.        typedef long double  extended;
  389.        typedef struct {extended Re, Im;} eComplex;
  390.    #else /* Watcom, Visual C++ */
  391.        typedef  double extended; /* Visual C++ and Optima++ do 
  392.                             not support 80-bit IEEE numbers. So 
  393.                             make extended equal to double    */
  394.        typedef dComplex  eComplex;
  395.    #endif    /* restore default data packing  */
  396. #endif
  397.  
  398. #else   // declare the complex classes for all three levels of precision
  399.         // Although these classes are fully compatible to the complex
  400.         // classes of the Standard C++ Library, keep them out of the
  401.         // standard namespace.
  402.  
  403. template <class T>
  404. class complex;
  405. class complex<float>;
  406. class complex<double>;
  407. class complex<long double>;
  408.  
  409. class complex<float>
  410. {
  411.   public:
  412.          // constructors:
  413.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x450
  414.         complex( float Re_part, float Im_part ) {Re=Re_part; Im=Im_part;}
  415.         complex( float Re_part )  {Re=Re_part; Im=0;}
  416.         complex() {}; // most efficient to have these as three different constructors!
  417.             // interconversions between the three levels of accuracy:
  418.             // with OVERFLOW error handling for the down-conversions
  419.     #else // problems with the template definitions in older versions
  420.         complex<float>( float Re_part, float Im_part ) {Re=Re_part; Im=Im_part;}
  421.         complex<float>( float Re_part )  {Re=Re_part; Im=0;}
  422.         complex<float>() {}; // most efficient to have these as three different constructors!
  423.         #ifndef __BORLANDC__
  424.             complex<float> (complex<float> _VFAR &);
  425.         #endif
  426.     #endif
  427.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x500
  428.         explicit complex (complex<double> _VFAR &);
  429.         explicit complex (complex<long double> _VFAR &);
  430.     #else
  431.         complex<float> (complex<double> _VFAR &);
  432.         complex<float> (complex<long double> _VFAR &);
  433.     #endif
  434.     friend complex<float> __cmf cdtocf( complex<double> cd );
  435.     friend complex<float> __cmf cetocf( complex<long double> ce );
  436.        // simple assignments: no OVERFLOW error handling
  437.     #ifndef __BORLANDC__
  438.         complex<float> _VFAR & __cmo  operator= (complex<float> _VFAR &);
  439.     #endif
  440.     complex<float> _VFAR & __cmo  operator= (complex<double> _VFAR &);
  441.     complex<float> _VFAR & __cmo  operator= (complex<long double> _VFAR &);
  442.  
  443.     // Cartesian complex from polar coordinates:
  444.     friend complex<float> __cmf polar(float _mag, float _angle=0);
  445.  
  446.     // basic operations:
  447.     float real() { return Re; }                              // real part
  448.     friend float __cmf real(complex<float> _VFAR &_z);
  449.     float imag() { return Im; }                              // imaginary part
  450.     friend float __cmf imag(complex<float> _VFAR &_z);
  451.     friend complex<float> __cmf neg(complex<float> _VFAR &); // same as unary operator -
  452.     friend complex<float> __cmf conj(complex<float> _VFAR &);// complex conjugate
  453.     friend float  __cmf norm(complex<float> _VFAR &);  // square of the magnitude
  454.     friend float  __cmf arg(complex<float>);           // angle in the plane
  455.  
  456.      // Unary operators
  457.     complex<float> _VFAR & __cmo operator+();
  458.     friend complex<float> __cmf operator-( complex<float> _VFAR &);
  459.  
  460.     // Binary operators:
  461.     friend complex<float> __cmf operator+(complex<float> _VFAR &, complex<float> _VFAR &);
  462.     friend complex<float> __cmf operator+(float, complex<float> _VFAR &);
  463.     friend complex<float> __cmf operator+(complex<float> _VFAR &, float);
  464.     friend complex<float> __cmf operator-(complex<float> _VFAR &, complex<float> _VFAR &);
  465.     friend complex<float> __cmf operator-(float, complex<float> _VFAR &);
  466.     friend complex<float> __cmf operator-(complex<float> _VFAR &, float);
  467.     friend complex<float> __cmf operator*(complex<float> _VFAR &, complex<float> _VFAR &);
  468.     friend complex<float> __cmf operator*(complex<float> _VFAR &, float);
  469.     friend complex<float> __cmf operator*(float, complex<float> _VFAR &);
  470.     friend complex<float> __cmf operator/(complex<float> _VFAR &, complex<float> _VFAR &);
  471.     friend complex<float> __cmf operator/(complex<float> _VFAR &, float);
  472.     friend complex<float> __cmf operator/(float, complex<float> _VFAR &);
  473.        // mixed-accuracy binary operators are declared at the higher-accuracy classes
  474.  
  475.     friend VBOOL __cmf operator==(complex<float> _VFAR &, complex<float> _VFAR &);
  476.     friend VBOOL __cmf operator==(complex<float> _VFAR &, float);
  477.     friend VBOOL __cmf operator!=(complex<float> _VFAR &, complex<float> _VFAR &);
  478.     friend VBOOL __cmf operator!=(complex<float> _VFAR &, float);
  479.  
  480.        //  Compound-assignment operators:
  481.     complex<float> _VFAR & __cmo  operator+= (complex<float> _VFAR &);
  482.     complex<float> _VFAR & __cmo  operator-= (complex<float> _VFAR &);
  483.     complex<float> _VFAR & __cmo  operator*= (complex<float> _VFAR &);
  484.     complex<float> _VFAR & __cmo  operator/= (complex<float> _VFAR &);
  485.  
  486.     complex<float> _VFAR & __cmo  operator+= (complex<double> _VFAR &);
  487.     complex<float> _VFAR & __cmo  operator-= (complex<double> _VFAR &);
  488.     complex<float> _VFAR & __cmo  operator*= (complex<double> _VFAR &);
  489.     complex<float> _VFAR & __cmo  operator/= (complex<double> _VFAR &);
  490.  
  491.     complex<float> _VFAR & __cmo  operator+= (complex<long double> _VFAR &);
  492.     complex<float> _VFAR & __cmo  operator-= (complex<long double> _VFAR &);
  493.     complex<float> _VFAR & __cmo  operator*= (complex<long double> _VFAR &);
  494.     complex<float> _VFAR & __cmo  operator/= (complex<long double> _VFAR &);
  495.  
  496.     // Overloaded ANSI C math functions
  497.     friend float          __cmf abs(complex<float>);
  498.     friend complex<float> __cmf acos(complex<float>);
  499.     friend complex<float> __cmf asin(complex<float>);
  500.     friend complex<float> __cmf atan(complex<float>);
  501.     friend complex<float> __cmf cos(complex<float>);
  502.     friend complex<float> __cmf cosh(complex<float>);
  503.     friend complex<float> __cmf cubic(complex<float>);  // raise to the third power
  504.     friend complex<float> __cmf exp(complex<float>);
  505.     friend complex<float> __cmf inv(complex<float>);    //   1.0 / z
  506.     friend complex<float> __cmf ipow(complex<float> __base, int __expon);  // integer power
  507.     friend complex<float> __cmf ln(complex<float>);
  508.     friend complex<float> __cmf log(complex<float>); // same as ln
  509.     friend complex<float> __cmf log2(complex<float>);
  510.     friend complex<float> __cmf log10(complex<float>);
  511.     friend complex<float> __cmf pow(complex<float> __base, float __expon);
  512.     friend complex<float> __cmf powReExpo(complex<float> __base, float __expon);
  513.     friend complex<float> __cmf pow(float __base, complex<float> __expon);
  514.     friend complex<float> __cmf powReBase(float __base, complex<float> __expon);
  515.     friend complex<float> __cmf pow(complex<float> __base, complex<float> __expon);
  516.     friend complex<float> __cmf quartic(complex<float>);  // raise to the fourth power
  517.     friend complex<float> __cmf sin(complex<float>);
  518.     friend complex<float> __cmf sinh(complex<float>);
  519.     friend complex<float> __cmf sqrt(complex<float>);
  520.     friend complex<float> __cmf square(complex<float>);
  521.     friend complex<float> __cmf tan(complex<float>);
  522.     friend complex<float> __cmf tanh(complex<float>);
  523.  
  524.     friend istream _VFAR & __cmf operator>> (istream _VFAR &, complex<float> _VFAR &);
  525.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &, complex<float> _VFAR &);
  526.  
  527.     float Re, Im;  // still public!
  528. };
  529.  
  530. class  complex<double>
  531. {
  532.   public:
  533.          // constructors:
  534.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x450
  535.         complex( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  536.         complex( double Re_part )  {Re=Re_part; Im=0;}
  537.         complex() {};
  538.             // interconversions between the three levels of accuracy:
  539.             // with OVERFLOW error handling for the down-conversions
  540.         complex (complex<float> _VFAR &);
  541.     #else // problems with the template definitions in older versions
  542.           complex<double>( double Re_part, double Im_part ) {Re=Re_part; Im=Im_part;}
  543.           complex<double>( double Re_part )  {Re=Re_part; Im=0;}
  544.           complex<double>() {};
  545.           complex<double> (complex<float> _VFAR &);
  546.         #ifndef __BORLANDC__
  547.             complex<double> (complex<double> _VFAR &);
  548.         #endif
  549.     #endif
  550.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x500
  551.         explicit complex (complex<long double> _VFAR &);
  552.     #else
  553.         complex<double> (complex<long double> _VFAR &);
  554.     #endif
  555.     friend complex<double> __cmf cetocd( complex<long double> ce );
  556.           // simple assignments: no OVERFLOW error handling
  557.     complex<double> _VFAR & __cmo  operator= (complex<float> _VFAR &);
  558.     #ifndef __BORLANDC__
  559.         complex<double> _VFAR & __cmo  operator= (complex<double> _VFAR &);
  560.     #endif
  561.     complex<double> _VFAR & __cmo  operator= (complex<long double> _VFAR &);
  562.  
  563.     // Cartesian complex from polar coordinates:
  564.     friend complex<double> __cmf polar(double __mag, double __angle=0);
  565.  
  566.     // basic operations:
  567.     double real() { return Re; }                              // real part
  568.     friend double __cmf real(complex<double> _VFAR &_z);
  569.     double imag() { return Im; }                              // imaginary part
  570.     friend double __cmf imag(complex<double> _VFAR &_z);
  571.     friend complex<double> __cmf neg(complex<double> _VFAR &); // same as unary operator -
  572.     friend complex<double> __cmf conj(complex<double> _VFAR &);// complex conjugate
  573.     friend double  __cmf norm(complex<double> _VFAR &);  // square of the magnitude
  574.     friend double  __cmf arg(complex<double>);          // the angle in the plane
  575.  
  576.      // Unary operators
  577.     complex<double> _VFAR & __cmo operator+();
  578.     friend complex<double>  __cmf operator-( complex<double> _VFAR &);
  579.  
  580.         // Binary operators:
  581.     friend complex<double> __cmf operator+(complex<double> _VFAR &, complex<double> _VFAR &);
  582.     friend complex<double> __cmf operator+(double, complex<double> _VFAR &);
  583.     friend complex<double> __cmf operator+(complex<double> _VFAR &, double);
  584.     friend complex<double> __cmf operator-(complex<double> _VFAR &, complex<double> _VFAR &);
  585.     friend complex<double> __cmf operator-(double, complex<double> _VFAR &);
  586.     friend complex<double> __cmf operator-(complex<double> _VFAR &, double);
  587.     friend complex<double> __cmf operator*(complex<double> _VFAR &, complex<double> _VFAR &);
  588.     friend complex<double> __cmf operator*(complex<double> _VFAR &, double);
  589.     friend complex<double> __cmf operator*(double, complex<double> _VFAR &);
  590.     friend complex<double> __cmf operator/(complex<double> _VFAR &, complex<double> _VFAR &);
  591.     friend complex<double> __cmf operator/(complex<double> _VFAR &, double);
  592.     friend complex<double> __cmf operator/(double, complex<double> _VFAR &);
  593.         // float-double mixed-accuracy versions:
  594.     friend complex<double> __cmf operator+(complex<float> _VFAR &, complex<double> _VFAR &);
  595.     friend complex<double> __cmf operator+(complex<double> _VFAR &, complex<float> _VFAR &);
  596.     friend complex<double> __cmf operator-(complex<float> _VFAR &, complex<double> _VFAR &);
  597.     friend complex<double> __cmf operator-(complex<double> _VFAR &, complex<float> _VFAR &);
  598.     friend complex<double> __cmf operator*(complex<float> _VFAR &, complex<double> _VFAR &);
  599.     friend complex<double> __cmf operator*(complex<double> _VFAR &, complex<float> _VFAR &);
  600.     friend complex<double> __cmf operator/(complex<float> _VFAR &, complex<double> _VFAR &);
  601.     friend complex<double> __cmf operator/(complex<double> _VFAR &, complex<float> _VFAR &);
  602.  
  603.     friend VBOOL __cmf operator==(complex<double> _VFAR &, complex<double> _VFAR &);
  604.     friend VBOOL __cmf operator==(complex<double> _VFAR &, double);
  605.     friend VBOOL __cmf operator!=(complex<double> _VFAR &, complex<double> _VFAR &);
  606.     friend VBOOL __cmf operator!=(complex<double> _VFAR &, double);
  607.  
  608.        //  Compound-assignment operators:
  609.     complex<double> _VFAR & __cmo  operator+= (complex<float> _VFAR &);
  610.     complex<double> _VFAR & __cmo  operator-= (complex<float> _VFAR &);
  611.     complex<double> _VFAR & __cmo  operator*= (complex<float> _VFAR &);
  612.     complex<double> _VFAR & __cmo  operator/= (complex<float> _VFAR &);
  613.  
  614.     complex<double> _VFAR & __cmo  operator+= (complex<double> _VFAR &);
  615.     complex<double> _VFAR & __cmo  operator-= (complex<double> _VFAR &);
  616.     complex<double> _VFAR & __cmo  operator*= (complex<double> _VFAR &);
  617.     complex<double> _VFAR & __cmo  operator/= (complex<double> _VFAR &);
  618.  
  619.     complex<double> _VFAR & __cmo  operator+= (complex<long double> _VFAR &);
  620.     complex<double> _VFAR & __cmo  operator-= (complex<long double> _VFAR &);
  621.     complex<double> _VFAR & __cmo  operator*= (complex<long double> _VFAR &);
  622.     complex<double> _VFAR & __cmo  operator/= (complex<long double> _VFAR &);
  623.  
  624.     // Overloaded ANSI C math functions
  625.     friend double          __cmf abs(complex<double>);
  626.     friend complex<double> __cmf acos(complex<double>);
  627.     friend complex<double> __cmf asin(complex<double>);
  628.     friend complex<double> __cmf atan(complex<double>);
  629.     friend complex<double> __cmf cos(complex<double>);
  630.     friend complex<double> __cmf cosh(complex<double>);
  631.     friend complex<double> __cmf cubic(complex<double>);  // raise to the third power
  632.     friend complex<double> __cmf exp(complex<double>);
  633.     friend complex<double> __cmf inv(complex<double>);    //   1.0 / z
  634.     friend complex<double> __cmf ipow(complex<double> __base, int __expon);  // integer power
  635.     friend complex<double> __cmf ln(complex<double>);
  636.     friend complex<double> __cmf log(complex<double>); // same as ln
  637.     friend complex<double> __cmf log2(complex<double>);
  638.     friend complex<double> __cmf log10(complex<double>);
  639.     friend complex<double> __cmf pow(complex<double> __base, double __expon);
  640.     friend complex<double> __cmf powReExpo(complex<double> __base, double __expon);
  641.     friend complex<double> __cmf pow(double __base, complex<double> __expon);
  642.     friend complex<double> __cmf powReBase(double __base, complex<double> __expon);
  643.     friend complex<double> __cmf pow(complex<double> __base, complex<double> __expon);
  644.     friend complex<double> __cmf quartic(complex<double>);  // raise to the fourth power
  645.     friend complex<double> __cmf sin(complex<double>);
  646.     friend complex<double> __cmf sinh(complex<double>);
  647.     friend complex<double> __cmf sqrt(complex<double>);
  648.     friend complex<double> __cmf square(complex<double>);
  649.     friend complex<double> __cmf tan(complex<double>);
  650.     friend complex<double> __cmf tanh(complex<double>);
  651.  
  652.     friend istream _VFAR & __cmf operator>> (istream _VFAR &, complex<double> _VFAR &);
  653.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &, complex<double> _VFAR &);
  654.  
  655.     double Re, Im;  // still public!
  656. };
  657.  
  658. class complex<long double>
  659. {
  660.   public:
  661.          // constructors:
  662.     #if defined __BORLANDC__ && __BORLANDC__ >= 0x450
  663.         complex( long double Re_part, long double Im_part ) {Re=Re_part; Im=Im_part;}
  664.         complex( long double Re_part )  {Re=Re_part; Im=0;}
  665.         complex() {};
  666.             // interconversions between the three levels of accuracy:
  667.         complex (complex<float> _VFAR &);
  668.         complex (complex<double> _VFAR &);
  669.      #else // problems with the template definitions in older versions
  670.         complex<long double>( long double Re_part, long double Im_part ) {Re=Re_part; Im=Im_part;}
  671.         complex<long double>( long double Re_part )  {Re=Re_part; Im=0;}
  672.         complex<long double>() {};
  673.                 // interconversions between the three levels of accuracy:
  674.         complex<long double> (complex<float> _VFAR &);
  675.         complex<long double> (complex<double> _VFAR &);
  676.         #ifndef __BORLANDC__
  677.             complex<long double> (complex<long double> _VFAR &);
  678.         #endif
  679.      #endif
  680.           // simple assignments do the same:
  681.     complex<long double> _VFAR & __cmo  operator=  (complex<float> _VFAR &);
  682.     complex<long double> _VFAR & __cmo  operator=  (complex<double> _VFAR &);
  683.     #ifndef __BORLANDC__
  684.         complex<long double> _VFAR & __cmo  operator=  (complex<long double> _VFAR &);
  685.     #endif
  686.  
  687.           // Cartesian complex from polar coordinates:
  688.     friend complex<long double> __cmf polar(long double __mag, long double __angle=0);
  689.         // basic operations:
  690.     long double real() { return Re; }                              // real part
  691.     friend long double __cmf real(complex<long double> _VFAR &_z);
  692.     long double imag() { return Im; }                              // imaginary part
  693.     friend long double __cmf imag(complex<long double> _VFAR &_z);
  694.     friend complex<long double> __cmf neg(complex<long double> _VFAR &); // same as unary operator -
  695.     friend complex<long double> __cmf conj(complex<long double> _VFAR &);// complex conjugate
  696.     friend long double  __cmf norm(complex<long double> _VFAR &);  // square of the magnitude
  697.     friend long double  __cmf arg(complex<long double>);          // the angle in the plane
  698.  
  699.      // Unary operators
  700.     complex<long double> _VFAR & __cmo operator+();
  701.     friend complex<long double>  __cmf operator-( complex<long double> _VFAR &);
  702.  
  703.         // Binary operators:
  704.     friend complex<long double> __cmf operator+(complex<long double> _VFAR &, complex<long double> _VFAR &);
  705.     friend complex<long double> __cmf operator+(long double, complex<long double> _VFAR &);
  706.     friend complex<long double> __cmf operator+(complex<long double> _VFAR &, long double);
  707.     friend complex<long double> __cmf operator-(complex<long double> _VFAR &, complex<long double> _VFAR &);
  708.     friend complex<long double> __cmf operator-(long double, complex<long double> _VFAR &);
  709.     friend complex<long double> __cmf operator-(complex<long double> _VFAR &, long double);
  710.     friend complex<long double> __cmf operator*(complex<long double> _VFAR &, complex<long double> _VFAR &);
  711.     friend complex<long double> __cmf operator*(complex<long double> _VFAR &, long double);
  712.     friend complex<long double> __cmf operator*(long double, complex<long double> _VFAR &);
  713.     friend complex<long double> __cmf operator/(complex<long double> __dividend,
  714.                                                 complex<long double> __divisor);
  715.     friend complex<long double> __cmf operator/(complex<long double> _VFAR &, long double );
  716.     friend complex<long double> __cmf operator/(long double __dividend,
  717.                                                 complex<long double> __divisor);
  718.         // mixed-accuracy versions:
  719.     friend complex<long double> __cmf operator+(complex<float> _VFAR &, complex<long double> _VFAR &);
  720.     friend complex<long double> __cmf operator+(complex<long double> _VFAR &, complex<float> _VFAR &);
  721.     friend complex<long double> __cmf operator+(complex<double> _VFAR &, complex<long double> _VFAR &);
  722.     friend complex<long double> __cmf operator+(complex<long double> _VFAR &, complex<double> _VFAR &);
  723.     friend complex<long double> __cmf operator-(complex<float> _VFAR &, complex<long double> _VFAR &);
  724.     friend complex<long double> __cmf operator-(complex<long double> _VFAR &, complex<float> _VFAR &);
  725.     friend complex<long double> __cmf operator-(complex<double> _VFAR &, complex<long double> _VFAR &);
  726.     friend complex<long double> __cmf operator-(complex<long double> _VFAR &, complex<double> _VFAR &);
  727.     friend complex<long double> __cmf operator*(complex<float> _VFAR &, complex<long double> _VFAR &);
  728.     friend complex<long double> __cmf operator*(complex<long double> _VFAR &, complex<float> _VFAR &);
  729.     friend complex<long double> __cmf operator*(complex<double> _VFAR &, complex<long double> _VFAR &);
  730.     friend complex<long double> __cmf operator*(complex<long double> _VFAR &, complex<double> _VFAR &);
  731.     friend complex<long double> __cmf operator/(complex<long double> _VFAR & __dividend,
  732.                                                 complex<float> _VFAR & __divisor);
  733.     friend complex<long double> __cmf operator/(complex<long double> _VFAR & __dividend,
  734.                                                 complex<double> _VFAR & __divisor);
  735.         // no explicit version for mixed division involving complex<long double>
  736.         // as the divisor; rely on implicit conversion of the dividend and use
  737.         // the operator /( complex<long double>, complex<long double> ).
  738.  
  739.     friend VBOOL __cmf operator==(complex<long double> _VFAR &, complex<long double> _VFAR &);
  740.     friend VBOOL __cmf operator==(complex<long double> _VFAR &, long double);
  741.     friend VBOOL __cmf operator!=(complex<long double> _VFAR &, complex<long double> _VFAR &);
  742.     friend VBOOL __cmf operator!=(complex<long double> _VFAR &, long double);
  743.  
  744.        //  Compound-assignment operators:
  745.     complex<long double> _VFAR & __cmo  operator+= (complex<float> _VFAR &);
  746.     complex<long double> _VFAR & __cmo  operator-= (complex<float> _VFAR &);
  747.     complex<long double> _VFAR & __cmo  operator*= (complex<float> _VFAR &);
  748.     complex<long double> _VFAR & __cmo  operator/= (complex<float> _VFAR &);
  749.  
  750.     complex<long double> _VFAR & __cmo  operator+= (complex<double> _VFAR &);
  751.     complex<long double> _VFAR & __cmo  operator-= (complex<double> _VFAR &);
  752.     complex<long double> _VFAR & __cmo  operator*= (complex<double> _VFAR &);
  753.     complex<long double> _VFAR & __cmo  operator/= (complex<double> _VFAR &);
  754.  
  755.     complex<long double> _VFAR & __cmo  operator+= (complex<long double> _VFAR &);
  756.     complex<long double> _VFAR & __cmo  operator-= (complex<long double> _VFAR &);
  757.     complex<long double> _VFAR & __cmo  operator*= (complex<long double> _VFAR &);
  758.     complex<long double> _VFAR & __cmo  operator/= (complex<long double> _VFAR &);
  759.  
  760.     // Overloaded ANSI C math functions
  761.     friend long double          __cmf abs(complex<long double>);
  762.     friend complex<long double> __cmf acos(complex<long double>);
  763.     friend complex<long double> __cmf asin(complex<long double>);
  764.     friend complex<long double> __cmf atan(complex<long double>);
  765.     friend complex<long double> __cmf cos(complex<long double>);
  766.     friend complex<long double> __cmf cosh(complex<long double>);
  767.     friend complex<long double> __cmf cubic(complex<long double>);  // raise to the third power
  768.     friend complex<long double> __cmf exp(complex<long double>);
  769.     friend complex<long double> __cmf inv(complex<long double>);    //   1.0 / z
  770.     friend complex<long double> __cmf ipow(complex<long double> __base, int __expon);  // integer power
  771.     friend complex<long double> __cmf ln(complex<long double>);
  772.     friend complex<long double> __cmf log(complex<long double>); // same as ln
  773.     friend complex<long double> __cmf log2(complex<long double>);
  774.     friend complex<long double> __cmf log10(complex<long double>);
  775.     friend complex<long double> __cmf pow(complex<long double> __base, long double __expon);
  776.     friend complex<long double> __cmf powReExpo(complex<long double> __base, long double __expon);
  777.     friend complex<long double> __cmf pow(long double __base, complex<long double> __expon);
  778.     friend complex<long double> __cmf powReBase(long double __base, complex<long double> __expon);
  779.     friend complex<long double> __cmf pow(complex<long double> __base, complex<long double> __expon);
  780.     friend complex<long double> __cmf quartic(complex<long double>);  // raise to the fourth power
  781.     friend complex<long double> __cmf sin(complex<long double>);
  782.     friend complex<long double> __cmf sinh(complex<long double>);
  783.     friend complex<long double> __cmf sqrt(complex<long double>);
  784.     friend complex<long double> __cmf square(complex<long double>);
  785.     friend complex<long double> __cmf tan(complex<long double>);
  786.     friend complex<long double> __cmf tanh(complex<long double>);
  787.  
  788.     friend istream _VFAR & __cmf operator>> (istream _VFAR &,
  789.                                              complex<long double> _VFAR &);
  790.     friend ostream _VFAR & __cmf operator<< (ostream _VFAR &,
  791.                                              complex<long double> _VFAR &);
  792.     long double Re, Im; // still public!
  793. };
  794. #ifndef _CMATH_DEFS
  795.     typedef long double extended;
  796.     typedef complex<float>      fComplex;
  797.     typedef complex<double>     dComplex;
  798.     typedef complex<extended>   eComplex;
  799.     #define _CMATH_DEFS
  800. #endif  // _CMATH_DEFS
  801.  
  802. // inline-implementation of the simple functions and operators
  803.  
  804. //  data-type interconverting constructors:
  805. //  in the down-conversions, OVERFLOW errors are handled via _matherr
  806. inline complex<float>::complex (complex<double> _VFAR & zd){ *this = cdtocf( zd ); }
  807. inline complex<float>::complex (complex<long double> _VFAR & ze){*this = cetocf( ze );}
  808. inline complex<double>::complex (complex<float> _VFAR & zf){Re = zf.Re; Im = zf.Im; }
  809. inline complex<double>::complex (complex<long double> _VFAR & ze){*this = cetocd( ze );}
  810. inline complex<long double>::complex (complex<float> _VFAR & zf){Re=zf.Re; Im=zf.Im;}
  811. inline complex<long double>::complex (complex<double> _VFAR & zd){Re=zd.Re; Im=zd.Im;}
  812. #ifndef __BORLANDC__
  813.     inline complex<float>::complex (complex<float> _VFAR & zf){ Re = zf.Re; Im = zf.Im;}
  814.     inline complex<double>::complex (complex<double> _VFAR & zd){Re = zd.Re; Im = zd.Im; }
  815.     inline complex<long double>::complex (complex<long double> _VFAR & ze){Re=ze.Re; Im=ze.Im;}
  816. #endif
  817.  
  818. //  simple assignments:
  819. inline complex<float> _VFAR & complex<float>::operator= (complex<double> _VFAR & __z)
  820. {   Re = __z.Re; Im = __z.Im; return *this; }
  821. inline complex<float> _VFAR & complex<float>::operator= (complex<long double> _VFAR & __z)
  822. {   Re = __z.Re; Im = __z.Im; return *this; }
  823. inline complex<double> _VFAR & complex<double>::operator= (complex<float> _VFAR & __z)
  824. {   Re = __z.Re; Im = __z.Im; return *this; }
  825. inline complex<double> _VFAR & complex<double>::operator= (complex<long double> _VFAR & __z)
  826. {   Re = __z.Re; Im = __z.Im; return *this; }
  827. inline complex<long double> _VFAR & complex<long double>::operator= (complex<float> _VFAR & __z)
  828. {   Re = __z.Re; Im = __z.Im; return *this; }
  829. inline complex<long double> _VFAR & complex<long double>::operator= (complex<double> _VFAR & __z)
  830. {   Re = __z.Re; Im = __z.Im; return *this; }
  831. #ifndef __BORLANDC__
  832.     inline complex<float> _VFAR & __cmo complex<float>::operator= (complex<float> _VFAR & __z)
  833.     {   Re = __z.Re; Im = __z.Im; return *this; }
  834.     inline complex<double> _VFAR & complex<double>::operator= (complex<double> _VFAR & __z)
  835.     {   Re = __z.Re; Im = __z.Im; return *this; }
  836.     inline complex<long double> _VFAR & complex<long double>::operator= (complex<long double> _VFAR & __z)
  837.     {   Re = __z.Re; Im = __z.Im; return *this; }
  838. #endif
  839.  
  840. // basic operations:
  841. template<class T>
  842. inline T __cmf real( complex<T> _VFAR & __z) { return __z.Re; }
  843.  
  844. template<class T>
  845. inline T __cmf imag( complex<T> _VFAR & __z) { return __z.Im; }
  846.  
  847. template <class T>
  848. inline complex<T> __cmf neg( complex<T> _VFAR & __z )
  849. {   return complex<T>(-__z.Re, -__z.Im); }
  850.  
  851. template <class T>
  852. inline complex<T> __cmf conj( complex<T> _VFAR & __z )
  853. {   return complex<T>(__z.Re, -__z.Im); }
  854.  
  855. template <class T>
  856. inline T __cmf norm( complex<T> _VFAR & __z )
  857. {   return __z.Re*__z.Re + __z.Im*__z.Im; }
  858.  
  859.          // Unary operators:
  860. template <class T>
  861. inline complex<T> _VFAR & __cmo complex<T>::operator+()
  862. {   return (*this); }
  863.  
  864. template <class T>
  865. inline complex<T> __cmf operator-( complex<T> _VFAR & __z)
  866. {   return complex<T>(-__z.Re, -__z.Im); }
  867.  
  868.         // Binary operators:
  869. template <class T>
  870. inline complex<T> __cmf operator+( complex<T> _VFAR & __z1, complex<T> _VFAR & __z2)
  871. {   return complex<T>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  872.  
  873. template <class T>
  874. inline complex<T> __cmf operator+( complex<T> _VFAR & __z1, T __z2Re )
  875. {   return complex<T>(__z1.Re+__z2Re, __z1.Im); }
  876.  
  877. template <class T>
  878. inline complex<T> __cmf operator+( T __z1Re, complex<T> _VFAR & __z2 )
  879. {   return complex<T>(__z1Re + __z2.Re, __z2.Im); }
  880.  
  881. template <class T>
  882. inline complex<T> __cmf operator-( complex<T> _VFAR & __z1, complex<T> _VFAR & __z2 )
  883. {   return complex<T>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  884.  
  885. template <class T>
  886. inline complex<T> __cmf operator-( complex<T> _VFAR & __z1, T __z2Re )
  887. {   return complex<T>(__z1.Re - __z2Re, __z1.Im); }
  888.  
  889. template <class T>
  890. inline complex<T> __cmf operator-( T __z1Re, complex<T> _VFAR & __z2 )
  891. {   return complex<T>(__z1Re - __z2.Re, -__z2.Im); }
  892.  
  893. template <class T>
  894. inline complex<T> __cmf operator*( complex<T> _VFAR & __z1, complex<T> _VFAR & __z2)
  895. {   return complex<T>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  896.                        __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  897. }
  898. template <class T>
  899. inline complex<T> __cmf operator*( complex<T> _VFAR & __z1, T __z2Re )
  900. {   return complex<T>( __z1.Re * __z2Re, __z1.Im * __z2Re ); }
  901.  
  902. template <class T>
  903. inline complex<T> __cmf operator*( T __z1Re, complex<T> _VFAR & __z2 )
  904. {   return complex<T>( __z1Re * __z2.Re, __z1Re * __z2.Im ); }
  905.  
  906. template <class T>
  907. inline complex<T> __cmf operator/( complex<T> _VFAR & __dividend, T __divisorRe)
  908. {   return complex<T>( __dividend.Re / __divisorRe, __dividend.Im / __divisorRe ); }
  909.  
  910. inline complex<float> __cmf operator/( complex<float> _VFAR & __dividend,
  911.                                        complex<float> _VFAR & __divisor )
  912. {     complex<float> Result;
  913.       double denom;
  914.       Result.Re = (float)((__dividend.Re *__divisor.Re +
  915.                            __dividend.Im *__divisor.Im) /
  916.          (denom = (double)(__divisor.Re) * __divisor.Re +
  917.                   (double)(__divisor.Im) * __divisor.Im));
  918.       Result.Im = (float)((__dividend.Im * __divisor.Re -
  919.                            __dividend.Re * __divisor.Im ) / denom);
  920.       return Result;
  921. }
  922.  
  923. inline complex<double> __cmf operator/( complex<double> _VFAR & __dividend,
  924.                                         complex<double> _VFAR & __divisor )
  925. {     complex<double> Result;
  926.       long double denom;
  927.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  928.                             __dividend.Im *__divisor.Im) /
  929.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  930.                   (long double)(__divisor.Im) * __divisor.Im));
  931.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  932.                             __dividend.Re * __divisor.Im ) / denom);
  933.       return Result;
  934. }
  935.     //   operator / (complex<long double>, complex<long double> )
  936.     //   cannot safely be inlined
  937.  
  938. inline complex<float> __cmf operator /( float __dividendRe,
  939.                                         complex<float> _VFAR & __divisor )
  940. {     complex<float> Result;
  941.       double         denom;
  942.       Result.Re = (float)((__dividendRe * __divisor.Re) /
  943.         (denom = (double)(__divisor.Re) * __divisor.Re +
  944.                  (double)(__divisor.Im) * __divisor.Im));
  945.       Result.Im = -(float)((__dividendRe * __divisor.Im ) / denom);
  946.       return Result;
  947. }
  948.  
  949. inline complex<double> __cmf operator /(double __dividendRe,
  950.                                         complex<double> _VFAR & __divisor )
  951. {     complex<double> Result;
  952.       long double     denom;
  953.       Result.Re = (double)((__dividendRe * __divisor.Re) /
  954.         (denom = (long double)(__divisor.Re) * __divisor.Re +
  955.                  (long double)(__divisor.Im) * __divisor.Im));
  956.       Result.Im = -(double)((__dividendRe * __divisor.Im ) / denom);
  957.       return Result;
  958. }
  959.     //   operator / (long double, complex<long double> )
  960.     //   cannot safely be inlined
  961.  
  962.     // Mixed-accuracy level binary operators:
  963. inline complex<double> __cmf operator+( complex<float> _VFAR & __z1, complex<double> _VFAR & __z2)
  964. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  965. inline complex<double> __cmf operator+( complex<double> _VFAR & __z1, complex<float> _VFAR & __z2)
  966. {   return complex<double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  967. inline complex<long double> __cmf operator+( complex<float> _VFAR & __z1, complex<long double> _VFAR & __z2)
  968. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  969. inline complex<long double> __cmf operator+( complex<long double> _VFAR & __z1, complex<float> _VFAR & __z2)
  970. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  971. inline complex<long double> __cmf operator+( complex<double> _VFAR & __z1, complex<long double> _VFAR & __z2)
  972. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  973. inline complex<long double> __cmf operator+( complex<long double> _VFAR & __z1, complex<double> _VFAR & __z2)
  974. {   return complex<long double>(__z1.Re + __z2.Re, __z1.Im + __z2.Im); }
  975.  
  976. inline complex<double> __cmf operator-( complex<float> _VFAR & __z1, complex<double> _VFAR & __z2)
  977. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  978. inline complex<double> __cmf operator-( complex<double> _VFAR & __z1, complex<float> _VFAR & __z2)
  979. {   return complex<double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  980. inline complex<long double> __cmf operator-( complex<float> _VFAR & __z1, complex<long double> _VFAR & __z2)
  981. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  982. inline complex<long double> __cmf operator-( complex<long double> _VFAR & __z1, complex<float> _VFAR & __z2)
  983. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  984. inline complex<long double> __cmf operator-( complex<double> _VFAR & __z1, complex<long double> _VFAR & __z2)
  985. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  986. inline complex<long double> __cmf operator-( complex<long double> _VFAR & __z1, complex<double> _VFAR & __z2)
  987. {   return complex<long double>(__z1.Re - __z2.Re, __z1.Im - __z2.Im); }
  988.  
  989. inline complex<double> __cmf operator*( complex<float> _VFAR & __z1, complex<double> __z2 )
  990. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  991.                             __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  992. }
  993. inline complex<double> __cmf operator*( complex<double> _VFAR & __z1, complex<float> __z2 )
  994. {   return complex<double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  995.                             __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  996. }
  997. inline complex<long double> __cmf operator*( complex<float> _VFAR & __z1, complex<long double> __z2 )
  998. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  999.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1000. }
  1001. inline complex<long double> __cmf operator*( complex<long double> _VFAR & __z1, complex<float> __z2 )
  1002. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1003.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1004. }
  1005. inline complex<long double> __cmf operator*( complex<double> _VFAR & __z1, complex<long double> __z2 )
  1006. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1007.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1008. }
  1009. inline complex<long double> __cmf operator*( complex<long double> _VFAR & __z1, complex<double> __z2 )
  1010. {   return complex<long double>( __z1.Re * __z2.Re - __z1.Im * __z2.Im,
  1011.                                  __z1.Re * __z2.Im + __z1.Im * __z2.Re );
  1012. }
  1013.  
  1014. inline complex<double> __cmf operator/( complex<float> _VFAR & __dividend,
  1015.                                         complex<double> _VFAR & __divisor )
  1016. {     complex<double> Result;
  1017.       long double     denom;
  1018.       Result.Re = (double)((__dividend.Re *__divisor.Re +
  1019.                             __dividend.Im *__divisor.Im) /
  1020.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  1021.                   (long double)(__divisor.Im) * __divisor.Im));
  1022.       Result.Im = (double)((__dividend.Im * __divisor.Re -
  1023.                             __dividend.Re * __divisor.Im ) / denom);
  1024.       return Result;
  1025. }
  1026.  
  1027. inline complex<double> __cmf operator/( complex<double> _VFAR & __dividend,
  1028.                                         complex<float>  _VFAR & __divisor )
  1029. {     complex<double> Result;
  1030.       double          denom;
  1031.       Result.Re = (__dividend.Re *__divisor.Re +
  1032.                    __dividend.Im *__divisor.Im) /
  1033.          (denom = (double)(__divisor.Re) * __divisor.Re +
  1034.                   (double)(__divisor.Im) * __divisor.Im);
  1035.       Result.Im = (__dividend.Im * __divisor.Re -
  1036.                    __dividend.Re * __divisor.Im ) / denom;
  1037.       return Result;
  1038. }
  1039.  
  1040. inline complex<long double> __cmf operator/( complex<long double> _VFAR & __dividend,
  1041.                                              complex<float>  _VFAR & __divisor )
  1042. {     complex<long double> Result;
  1043.       double               denom;
  1044.       Result.Re = (__dividend.Re *__divisor.Re +
  1045.                    __dividend.Im *__divisor.Im) /
  1046.          (denom = (double)(__divisor.Re) * __divisor.Re +
  1047.                   (double)(__divisor.Im) * __divisor.Im);
  1048.       Result.Im = (__dividend.Im * __divisor.Re -
  1049.                    __dividend.Re * __divisor.Im ) / denom;
  1050.       return Result;
  1051. }
  1052.  
  1053. inline complex<long double> __cmf operator/( complex<long double> _VFAR & __dividend,
  1054.                                              complex<double>  _VFAR & __divisor )
  1055. {     complex<long double> Result;
  1056.       long double          denom;
  1057.       Result.Re = (__dividend.Re *__divisor.Re +
  1058.                    __dividend.Im *__divisor.Im) /
  1059.          (denom = (long double)(__divisor.Re) * __divisor.Re +
  1060.                   (long double)(__divisor.Im) * __divisor.Im);
  1061.       Result.Im = (__dividend.Im * __divisor.Re -
  1062.                    __dividend.Re * __divisor.Im ) / denom;
  1063.       return Result;
  1064. }
  1065.  
  1066. template <class T>
  1067. inline VBOOL __cmf operator== (complex<T> _VFAR & __z1, complex<T> _VFAR & __z2)
  1068. {   return __z1.Re == __z2.Re && __z1.Im == __z2.Im; }
  1069.  
  1070. template <class T>
  1071. inline VBOOL __cmf operator== (T __z1Re, complex<T> _VFAR & __z2)
  1072. {   return __z1Re == __z2.Re && __z2.Im == 0; }
  1073.  
  1074. template <class T>
  1075. inline VBOOL __cmf operator== (complex<T> _VFAR & __z1, T __z2Re)
  1076. {   return __z1.Re == __z2Re && __z1.Im == 0; }
  1077.  
  1078. template <class T>
  1079. inline VBOOL __cmf operator!= (complex<T> _VFAR & __z1, complex<T> _VFAR & __z2)
  1080. {   return __z1.Re != __z2.Re || __z1.Im != __z2.Im; }
  1081.  
  1082. template <class T>
  1083. inline VBOOL __cmf operator!= (T __z1Re, complex<T> _VFAR & __z2)
  1084. {   return __z1Re != __z2.Re || __z2.Im != 0; }
  1085.  
  1086. template <class T>
  1087. inline VBOOL __cmf operator!= (complex<T> _VFAR & __z1, T __z2Re)
  1088. {   return __z1.Re != __z2Re || __z1.Im != 0; }
  1089.  
  1090.       // Compound-assignment operators:
  1091. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<float> _VFAR & __s2)
  1092. {   Re += __s2.real(); Im += __s2.imag(); return *this; }
  1093.  
  1094. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<double> _VFAR & __s2)
  1095. {   Re += __s2.real(); Im += __s2.imag(); return *this; }
  1096.  
  1097. inline complex<float> _VFAR & __cmo complex<float>::operator+= (complex<long double> _VFAR & __s2)
  1098. {   Re += __s2.real(); Im += __s2.imag(); return *this; }
  1099.  
  1100. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<float> _VFAR & __s2)
  1101. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1102.  
  1103. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<double> _VFAR & __s2)
  1104. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1105.  
  1106. inline complex<double> _VFAR & __cmo complex<double>::operator+= (complex<long double> _VFAR & __s2)
  1107. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1108.  
  1109. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<float> _VFAR & __s2)
  1110. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1111.  
  1112. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<double> _VFAR & __s2)
  1113. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1114.  
  1115. inline complex<long double> _VFAR & __cmo complex<long double>::operator+= (complex<long double> _VFAR & __s2)
  1116. {   Re += __s2.Re; Im += __s2.Im; return *this; }
  1117.  
  1118. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<float> _VFAR & __s2)
  1119. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1120.  
  1121. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<double> _VFAR & __s2)
  1122. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1123.  
  1124. inline complex<float> _VFAR & __cmo complex<float>::operator-= (complex<long double> _VFAR & __s2)
  1125. {   Re -= __s2.real(); Im -= __s2.imag(); return *this; }
  1126.  
  1127. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<float> _VFAR & __s2)
  1128. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1129.  
  1130. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<double> _VFAR & __s2)
  1131. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1132.  
  1133. inline complex<double> _VFAR & __cmo complex<double>::operator-= (complex<long double> _VFAR & __s2)
  1134. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1135.  
  1136. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<float> _VFAR & __s2)
  1137. {    Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1138.  
  1139. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<double> _VFAR & __s2)
  1140. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1141.  
  1142. inline complex<long double> _VFAR & __cmo complex<long double>::operator-= (complex<long double> _VFAR & __s2)
  1143. {   Re -= __s2.Re; Im -= __s2.Im; return *this; }
  1144.  
  1145. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<float> _VFAR & __fac2)
  1146. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1147.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1148.     Re          = tmpRe;
  1149.     return *this;
  1150. }
  1151.  
  1152. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<double> _VFAR & __fac2)
  1153. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1154.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1155.     Re          = tmpRe;
  1156.     return *this;
  1157. }
  1158.  
  1159. inline complex<float> _VFAR & __cmo complex<float>::operator*= (complex<long double> _VFAR & __fac2)
  1160. {   float tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1161.     Im          = Im * __fac2.Re + Re * __fac2.Im;
  1162.     Re          = tmpRe;
  1163.     return *this;
  1164. }
  1165.  
  1166. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<float> _VFAR & __fac2)
  1167. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1168.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1169.     Re           = tmpRe;
  1170.     return *this;
  1171. }
  1172.  
  1173. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<double> _VFAR & __fac2)
  1174. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1175.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1176.     Re           = tmpRe;
  1177.     return *this;
  1178. }
  1179.  
  1180. inline complex<double> _VFAR & __cmo complex<double>::operator*= (complex<long double> _VFAR & __fac2)
  1181. {   double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1182.     Im           = Im * __fac2.Re + Re * __fac2.Im;
  1183.     Re           = tmpRe;
  1184.     return *this;
  1185. }
  1186.  
  1187. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<float> _VFAR & __fac2)
  1188. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1189.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1190.     Re                = tmpRe;
  1191.     return *this;
  1192. }
  1193.  
  1194. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<double> _VFAR & __fac2)
  1195. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1196.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1197.     Re                = tmpRe;
  1198.     return *this;
  1199. }
  1200.  
  1201. inline complex<long double> _VFAR & __cmo complex<long double>::operator*= (complex<long double> _VFAR & __fac2)
  1202. {   long double tmpRe = Re * __fac2.Re - Im * __fac2.Im;
  1203.     Im                = Im * __fac2.Re + Re * __fac2.Im;
  1204.     Re                = tmpRe;
  1205.     return *this;
  1206. }
  1207.  
  1208. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<float> _VFAR & __divisor)
  1209. {     double denom;
  1210.       float  tmpRe = (float)((Re * __divisor.Re + Im * __divisor.Im) /
  1211.             (denom = (double)(__divisor.Re) * __divisor.Re +
  1212.                      (double)(__divisor.Im) * __divisor.Im));
  1213.       Im = (float)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1214.       Re = tmpRe;
  1215.       return *this;
  1216. }
  1217.  
  1218. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<double> _VFAR & __divisor)
  1219. {     long double denom;
  1220.       float tmpRe = (float)((Re * __divisor.Re + Im * __divisor.Im) /
  1221.            (denom = (long double)(__divisor.Re) * __divisor.Re +
  1222.                     (long double)(__divisor.Im) * __divisor.Im));
  1223.       Im = (float)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1224.       Re = tmpRe;
  1225.       return *this;
  1226. }
  1227.  
  1228. inline complex<float> _VFAR & __cmo complex<float>::operator/= (complex<long double> _VFAR & __divisor)
  1229. {   return(*this = complex<long double>(*this) / __divisor); }
  1230.  
  1231.  
  1232. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<float> _VFAR & __divisor)
  1233. {     double denom;
  1234.       double tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  1235.             (denom = (double)(__divisor.Re) * __divisor.Re +
  1236.                      (double)(__divisor.Im) * __divisor.Im));
  1237.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1238.       Re = tmpRe;
  1239.       return *this;
  1240. }
  1241.  
  1242. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<double> _VFAR & __divisor)
  1243. {     long double denom;
  1244.       double  tmpRe = (double)((Re * __divisor.Re + Im * __divisor.Im) /
  1245.              (denom = (long double)(__divisor.Re) * __divisor.Re +
  1246.                       (long double)(__divisor.Im) * __divisor.Im));
  1247.       Im = (double)((Im * __divisor.Re - Re * __divisor.Im ) / denom);
  1248.       Re = tmpRe;
  1249.       return *this;
  1250. }
  1251.  
  1252. inline complex<double> _VFAR & __cmo complex<double>::operator/= (complex<long double> _VFAR & __divisor)
  1253. {   return(*this = complex<long double>(*this) / __divisor); }
  1254.  
  1255. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<float> _VFAR & __divisor)
  1256. {     double denom;
  1257.       long double tmpRe = (Re * __divisor.Re + Im * __divisor.Im) /
  1258.                  (denom = (double)(__divisor.Re) * __divisor.Re +
  1259.                           (double)(__divisor.Im) * __divisor.Im);
  1260.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1261.       Re = tmpRe;
  1262.       return *this;
  1263. }
  1264.  
  1265. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<double> _VFAR & __divisor)
  1266. {     long double denom;
  1267.       long double tmpRe = (Re * __divisor.Re + Im * __divisor.Im) /
  1268.                  (denom = (long double)(__divisor.Re) * __divisor.Re +
  1269.                           (long double)(__divisor.Im) * __divisor.Im);
  1270.       Im = (Im * __divisor.Re - Re * __divisor.Im ) / denom;
  1271.       Re = tmpRe;
  1272.       return *this;
  1273. }
  1274.  
  1275. inline complex<long double> _VFAR & __cmo complex<long double>::operator/= (complex<long double> _VFAR & __divisor)
  1276. {    return (*this / __divisor); }
  1277.  
  1278. template <class T>
  1279. inline istream _VFAR &  __cmf operator>> (istream _VFAR & is, complex<T> _VFAR & __z)
  1280. {   // read a complex number __z in the form r or (r) or {r, i} or (r, i)
  1281.     T     r = 0, i = 0;
  1282.     char  c;
  1283.  
  1284.     is >> c;
  1285.     if (c == '(' || c == '{')  // notations (r), (r,i), or {r,i}
  1286.     {
  1287.         is >> r >> c;
  1288.         if (c == ',') { is >> i  >> c;}
  1289.         if (c != ')' && c != '}')   is.clear(ios::failbit);
  1290.     }
  1291.     else  // only real part
  1292.     {
  1293.         is.putback(c);
  1294.         is >> r;
  1295.     }
  1296.     if (is) { __z.Re = r; __z.Im = i; }
  1297.     return is;
  1298. }
  1299.  
  1300. template <class T>
  1301. inline ostream _VFAR &  __cmf operator<< (ostream _VFAR & os, complex<T> _VFAR & __z)
  1302. {   return os << "{" << __z.Re << "," << __z.Im << "}"; }
  1303.  
  1304. #endif // CMATH_CLASSIC_COMPLEX
  1305. #ifdef __BORLANDC__
  1306.       #pragma option -a.
  1307. #else /* Visual C++ */
  1308.       #pragma pack( pop )
  1309. #endif    /* restore default data packing  */
  1310.  
  1311.        // error handling functions, borrowed from VectorLib:
  1312. extern "C" {
  1313. void  __cmf  V_noteError( char _VFAR *fname, unsigned why );
  1314. void  __cmf  V_printErrorMsg( char _VFAR *ErrMsg );
  1315. void  __cmf  V_setErrorEventFile( char _VFAR *filename,  unsigned ScreenAndFile );
  1316. void  __cmf  V_closeErrorEventFile( void );
  1317.  
  1318. /*** translation of calls to matherr() into _matherr() for BorlandC 4.0+ ***
  1319.  ***  (necessary only to maintain compatibility with BorlandC 3.x)       ***/
  1320.  
  1321. #if (__BORLANDC__ >= 0x450) && !defined (__FLAT__)
  1322.      #if !defined( __MATH_H )
  1323.             #include <math.h>
  1324.      #endif
  1325.      int  _Cdecl _FARFUNC matherr (struct exception _VFAR *__e);
  1326.      #define NEWMATHERR  \
  1327.          int matherr( struct exception _VFAR *__e ) \
  1328.          {  return( _matherr( __e )); }
  1329. #else
  1330.      #define NEWMATHERR
  1331. #endif
  1332. }  // end of extern "C" statement
  1333.  
  1334. #undef VBOOL
  1335. #undef __cmf
  1336. #undef __cmo
  1337. typedef fComplex fcomplex;
  1338. typedef dComplex dcomplex;
  1339. typedef eComplex ecomplex;  // tolerate all-lower case
  1340. #endif  // __NEWCPLX_H
  1341.